<?php
/**
 * Created by PhpStorm.
 * User: Lenovo
 * Date: 2018/11/28
 * Time: 17:46
 */

namespace app\api\controller;

use app\api\model\Notice;
use think\Controller;
use think\Exception;

class Notices extends Controller
{
    //获取未处理的评论通知
    public function getevaluteNotices(){
        $userid=$_GET['userid'];
        $re=Notice::getevalutenotice($userid);
        if(!$re){
            AjaxReturn('0','请求内容不存在');
        }else{
            AjaxReturn('1','请求成功',$re);
        }
    }

    //获取未处理评论通知数量
    public function evalutenoticenum(){
        $userid=$_GET['userid'];
        try{
            $num=Notice::where('status',0)->where('type',3)->where('belongid',$userid)->count();
            $re=array($num);
            AjaxReturn('1','请求成功',$re);
        }catch (Exception $exception){
            AjaxReturn('0','请求失败');
        }
    }
    //处理评论状态
    public function updEvaluteStatus()
    {
        $id=$_GET['id'];
        try{
            $re=Notice::get($id);
            $re->status=1;
            $re->save();
            AjaxReturn('1','请求成功');
        }catch (Exception $exception){
            AjaxReturn('0','请求错误');
        }
    }
}